<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../../include/admincontent.jsp" %>
<link rel="stylesheet" href="../../../resources/js/plugins/layui/css/layui.css" />
<script src="../../../resources/js/plugins/layui/layui.all.js" type="text/javascript"></script>
<style>
    .searchform{
        line-height: 30px;
        background: #EEF1F8;
        padding: 3px 10px;
        margin: 0px;
        font-size: 12px;
        color: #666;
        text-align: left;
    }

</style>
<div id="location">当前位置：招聘实施管理 > 中专校园招聘</div>
<div id="Content">
    <!-- 筛选条件 -->
    <form class="layui-form" action="">
        <div id="searchbox" >
            <div class="layui-form-item searchform">
                <div class="layui-inline">
                    <label class="layui-form-label">招聘方案：</label>
                    <div class="layui-input-inline">
                        <select name="pid"  lay-search="" lay-filter="projects">${projects}</select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">责任部门：</label>
                    <div class="layui-input-inline">
                        <select name="deptcode" id="deptcode" lay-search="" lay-filter="deptcode"></select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button id="flows_searchbtn" type="button" class="layui-btn"><em class="ico16 search_16"></em>搜索</button>
                </div>
            </div>
        </div>
    </form>

    <div>
        <div class="layui-tab layui-tab-brief" lay-filter="flows">
            <ul class="layui-tab-title">

            </ul>
            <div class="layui-tab-content" >

            </div>

        </div>

    </div>

</div>

<script type="text/javascript">
    var nowflows='';
    var allflows=[];
    var element;
    var form ;

    layui.use(['form','util'], function(){
        form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.on('select(projects)', function(data){
            getAjax('${path}/Do/ZZCampus/getdept?pid=' + data.value, null, function (data) {
                $("select[name=deptcode]").html(data);
                form.render();
            });
        });
        //……
        //但是，如果你的HTML是动态生成的，自动渲染就会失效
        //因此你需要在相应的地方，执行下述方法来手动渲染，跟这类似的还有 element.init();
        form.render();
        var util = layui.util;
        //固定块
        util.fixbar({
            top: true
            , css: {right: 10, bottom: 10}
            , bgcolor: '#393D49'
        });
    });

    layui.use('element', function() {
        var $ = layui.jquery;
        element = layui.element;
        element.on('tab(flows)', function(elem){
            var clickIndex=elem.index;
            var iframeurl=$(this).attr('lay-url');
            var fid=$(this).attr('lay-id');
            if($(this).hasClass("layui-disabled")){
                layer.msg('尚未进入到该流程!',{icon:2,time:2000},function () {
                    if(clickIndex!=0){
                        element.tabChange('flows', nowflows);
                    }
                });
                return false;
            }else{
                $(".layui-tab-content").empty();
               // console.log($('select[name=deptcode]').val());
                $(".layui-tab-content").append(
                    '<div class="layui-tab-item layui-show" >' +
                    '<iframe id="mainiframe" src="'+iframeurl+'"  width="100%" height="100%"  frameborder="0" onload="changeFrameHeight()"></iframe>'+
                    '</div>');

            }

        });

    });

    $(document).ready(function () {

        $('#flows_searchbtn').click(function () {
            getFlowsList();
        });
    });

    function getFlowsList() {
        loadTab();
    }

    function loadTab(fid) {
        var tabJson=null;
        $.get('${path}/Do/ZZCampus/getFlowsJson_bak?pid=' + $('select[name=pid]').val() + '&deptcode=' + $('select[name=deptcode]').val(), null, function (data) {
            if(data.length>0){
                allflows.length=0;
                $('.layui-tab .layui-tab-title').empty();
                $(data).each(function (index,obj) {
                    allflows.push(obj.fid);
                    if(obj.state==0){
                        $('.layui-tab .layui-tab-title').append('<li class="layui-disabled" lay-id="'+obj.fid+'" lay-url="'+obj.url+'" >'+obj.txt+'</li>');
                    }else{
                        nowflows=obj.fid;
                        $('.layui-tab .layui-tab-title').append('<li  lay-id="'+obj.fid+'" lay-url="'+obj.url+'" >'+obj.txt+'</li>');
                    }
                });

                element.tabChange('flows', nowflows);
                element.render();
            }
        },"JSON");
    }

    function setIframeHeight(iframe) {
        if (iframe) {
            var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
            if (iframeWin.document.body) {
                iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
            }
        }
    };
    function changeFrameHeight(){

        setTimeout(function () {
            var ifm= document.getElementById("mainiframe");
            var cheight=document.documentElement.clientHeight;
            var oheight=document.documentElement.offsetHeight;
            var sheight=ifm.contentWindow.document.documentElement.offsetHeight;
            var soheight=ifm.contentWindow.document.documentElement.clientHeight;
          /*  if(sheight<=cheight){
                ifm.height=cheight;
            }else{
                ifm.height=sheight+oheight+10;
            }*/
            ifm.height=sheight;
            //ifm.height=cheight-soheight+10;
            //console.log("ifmHeight:"+ifm.height);
        },500)

    }

</script>
</body>
</html>